package com.firemoss.atonement.test.metadata.inspectors.property
{
	import com.firemoss.atonement.metadata.AtonementMetadata;
	import com.firemoss.atonement.metadata.DefaultMetadataBuilder;
	import com.firemoss.atonement.metadata.IMetadataBuilder;
	import com.firemoss.atonement.metadata.Property;
	import com.firemoss.atonement.metadata.PropertyMetadata;
	import com.firemoss.atonement.test.mapper.MapperTests;
	import com.firemoss.atonement.test.mapper.objects.AddressDTO;
	import com.firemoss.atonement.test.mapper.objects.ContactDTO;
	import com.firemoss.atonement.test.metadata.inspectors.property.objects.SimpleObject;
	
	import org.flexunit.asserts.assertFalse;
	import org.flexunit.asserts.assertNotNull;
	import org.flexunit.asserts.assertTrue;

	public class PropertyInspectorTests
	{
		private var metadataBuilder:IMetadataBuilder = new DefaultMetadataBuilder();

		[Test]
		public function property_inspector_finds_properties_and_accessors_and_their_types() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new SimpleObject() );
			var pmd : PropertyMetadata = md.propertyMetadata
			
			assertNotNull( pmd );
			
			assertTrue( pmd.containsProperty( "propertyProperty" ) );
			assertTrue( pmd.containsProperty( "getterProperty" ) );
			
			assertTrue( pmd.getProperty( "getterProperty" ).type == pmd.getProperty( "propertyProperty" ).type );
		}
		
		[Test]
		public function property_inspector_only_finds_public_properties() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new SimpleObject() );
			var pmd : PropertyMetadata = md.propertyMetadata
				
			assertFalse( pmd.containsProperty( "privateProperty" ) );
		}

		[Test]
		public function property_inspector_finds_ignored_properties() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new ContactDTO() );
			var pmd : PropertyMetadata = md.propertyMetadata
			var prop : Property = pmd.getProperty( "ignoredProperty" )

			assertFalse( new Property().ignored )
			assertTrue( prop.ignored )
		}
		
		[Test]
		public function property_inspector_finds_property_resolvers() : void
		{
			// force this class in...refactor to something neutral, one day
			var foo : MapperTests = new MapperTests()
				
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new AddressDTO() );
			var pmd : PropertyMetadata = md.propertyMetadata
			var prop : Property = pmd.getProperty( "addressAsOneLine" )
			
			assertTrue( new Property().valueResolutionFunction == null )
			assertFalse( prop.valueResolutionFunction == null )
		}
		
		[Test]
		public function property_inspector_finds_collectionOf_tags() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new ContactDTO() );
			var pmd : PropertyMetadata = md.propertyMetadata
			var prop : Property = pmd.getProperty( "addressList" )
			
			assertTrue( new Property().collectionOf == null )
			assertTrue( prop.collectionOf == AddressDTO )
		}
		
	}
}